package com.chittoda.koncurrent.scheduling;

public class RoundRobinScheduling extends AbstractSchedule {

	private Integer indexer = -1;

	public RoundRobinScheduling(int size) {
		super(size);
	}
	
	@Override
	public int getNextIndex() {
		int index;
		
		//When size is 1, directly return 0 index 
		if(size == 1)
			return 0;
		
		synchronized (indexer) {
			if(indexer >= size-1)
				indexer = -1;
			
			index = ++indexer;
		}
		
		return index;
	}
	
	
}
